home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- import compiler
- import os
- import test.test_support as test
- import unittest
- from random import random
-
- class CompilerTest(unittest.TestCase):
-
- def testCompileLibrary(self):
- libdir = os.path.dirname(unittest.__file__)
- testdir = os.path.dirname(test.test_support.__file__)
- for dir in [
- libdir,
- testdir]:
- for basename in os.listdir(dir):
- if not basename.endswith('.py'):
- continue
-
- if not TEST_ALL and random() < 0.97999999999999998:
- continue
-
- path = os.path.join(dir, basename)
- if test.test_support.verbose:
- print 'compiling', path
-
- f = open(path, 'U')
- buf = f.read()
- f.close()
- if 'badsyntax' in basename:
- self.assertRaises(SyntaxError, compiler.compile, buf, basename, 'exec')
- continue
- compiler.compile(buf, basename, 'exec')
-
-
-
-
- def testLineNo(self):
- filename = __file__
- if filename.endswith('.pyc') or filename.endswith('.pyo'):
- filename = filename[:-1]
-
- tree = compiler.parseFile(filename)
- self.check_lineno(tree)
-
-
- def check_lineno(self, node):
-
- try:
- self._check_lineno(node)
- except AssertionError:
- print node.__class__, node.lineno
- raise
-
-
-
- def _check_lineno(self, node):
- if node.__class__ not in NOLINENO:
- self.assert_(isinstance(node.lineno, int), 'lineno=%s on %s' % (node.lineno, node.__class__))
- self.assert_(node.lineno > 0, 'lineno=%s on %s' % (node.lineno, node.__class__))
-
- for child in node.getChildNodes():
- self.check_lineno(child)
-
-
-
- NOLINENO = (compiler.ast.Module, compiler.ast.Stmt, compiler.ast.Discard)
-
- class Toto:
- '''docstring'''
- pass
-
- (a, b) = (2, 3)
- (c, d) = (5, 6)
- l = [ (x, y) for x, y in zip(range(5), range(5, 10)) ]
- l[0]
- l[3:4]
-
- try:
- print yo
- except:
- None if l else []
- yo = 3
-
- yo += 3
-
- try:
- a += b
- finally:
- b = 0
-
- from math import *
-
- def test_main():
- global TEST_ALL
- TEST_ALL = test.test_support.is_resource_enabled('compiler')
- test.test_support.run_unittest(CompilerTest)
-
- if __name__ == '__main__':
- test_main()
-
-